package com.example.hqpatrol.adapter;

import android.graphics.Color;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.hqpatrol.R;
import com.example.hqpatrol.entity.patrol.PatrolSimple;
import com.xuexiang.xui.adapter.recyclerview.BaseRecyclerAdapter;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
import com.xuexiang.xui.widget.imageview.RadiusImageView;
import com.xuexiang.xui.widget.layout.XUILinearLayout;

import java.util.Collection;

import cn.hutool.core.util.StrUtil;

public class PatrolListAdapter extends BaseRecyclerAdapter<PatrolSimple> {

    public PatrolListAdapter() {
    }

    public PatrolListAdapter(Collection<PatrolSimple> list) {
        super(list);
    }

    @Override
    protected int getItemLayoutId(int viewType) {
        return R.layout.layout_patrol_list_card;
    }

    @Override
    protected void bindData(@NonNull RecyclerViewHolder holder, int position, PatrolSimple item) {
        XUILinearLayout patrol_card_card = holder.findViewById(R.id.patrol_card_card);

        RadiusImageView patrol_card_title_icon = holder.findViewById(R.id.patrol_card_title_icon);
        patrol_card_title_icon.setImageResource(getIcon(item.getStep()));

        TextView patrol_card_title_text = holder.findViewById(R.id.patrol_card_title_text);
        patrol_card_title_text.setText(getTitleText(item.getStep()));

        TextView patrol_card_title_unit = holder.findViewById(R.id.patrol_card_title_unit);
        patrol_card_title_unit.setText(item.getRate() + item.getUnit() + "一次");

        TextView patrol_card_content = holder.findViewById(R.id.patrol_card_content);
        patrol_card_content.setText(item.getPatrolObject());

        TextView patrol_card_require_time = holder.findViewById(R.id.patrol_card_require_time);
        patrol_card_require_time.setText(item.getRequireTime());

        TextView patrol_card_user_name = holder.findViewById(R.id.patrol_card_user_name);
        if(item.getStep() == 2){
            patrol_card_user_name.setText(item.getPatrolUserName());
        }else{
            patrol_card_user_name.setText(item.getUserName());
        }
    }

    private int getIcon(int step) {
        switch (step){
            case 0: return R.drawable.ic_patrol_ready;
            case 1: return R.drawable.ic_patrol_finished;
            case 2: return R.drawable.ic_patrol_timeout;
            default: return R.drawable.ic_cry;
        }
    }

    private int getTitleText(int step) {
        switch (step){
            case 0: return R.string.patrol_ready;
            case 1: return R.string.patrol_finished;
            case 2: return R.string.patrol_timeout;
            default: return R.string.app_name;
        }
    }
}
